package com.ias.agdis_r.view.control;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.ias.agdis_r.R;
import com.ias.agdis_r.bean.other.TempLabelBean;
import com.ias.agdis_r.util.S;
import com.ias.agdis_r.view.base.BaseGroupView;

/**
 * Group1TypeView 显示内容格式为: XXX：XXX XXX：XXX XXX：XXX XXX：XXX
 * 
 * @param context
 * @author zhangsc
 */
public class Group1TypeView extends BaseGroupView {

	public Group1TypeView(Context context, ProgressBar progress) {
		super(context, progress);
		// TODO Auto-generated constructor stub
	}

	private LinearLayout.LayoutParams child1lp;
	private LinearLayout.LayoutParams child2lp;
	private LinearLayout child1Layout;

	@Override
	protected void init() {
		// TODO Auto-generated method stub
		// 设置自身布局为垂直布局
		this.setOrientation(LinearLayout.VERTICAL);
		child1lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);
		child1lp.topMargin = 4;
		child2lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT, 1.0f);
	}

	@Override
	public boolean addViewByTag(String infoTag, TempLabelBean labelBean) {
		// TODO Auto-generated method stub
		try {
			this.viewNum++;
			// 如果VIEW数量是奇数为，创建一个一级子Layout(每个一级子Layout里包含两个二级子Layout)
			if (this.viewNum % 2 == 1) {
				child1Layout = new LinearLayout(getContext());
				child1Layout.setLayoutParams(child1lp);
				child1Layout.setOrientation(LinearLayout.HORIZONTAL);
				addView(child1Layout);
				ImageView imageView = new ImageView(getContext());
				imageView.setLayoutParams(new LayoutParams(
						LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
				imageView.setPadding(12, 0, 12, 8);
				imageView.setImageResource(R.drawable.line3);
				addView(imageView);
			}
			// 创建一个二级子Layout
			LinearLayout child2Layout = new LinearLayout(getContext());
			child2Layout.setLayoutParams(child2lp);
			child2Layout.setOrientation(LinearLayout.HORIZONTAL);
			// 标题
			TextView labelView = new TextView(getContext());
			if(S.isEmpty(labelBean.getContent())){
				labelView.setText(labelBean.getContent());
			}else{
				labelView.setText(labelBean.getContent()+":");
			}
			labelView.setTextSize(20);
			labelView.setPadding(12, 4, 12, 2);
			labelView.setTextColor(Color.BLACK);
			child2Layout.addView(labelView);
			// 内容
			TextView infoView = new TextView(getContext());
			infoView.setTag(infoTag);
			infoView.setTextSize(20);
			child2Layout.addView(infoView);
			// System.out.println("##########TAG:"+taskLabelBean.getType()+"|URL:"+taskLabelBean.getUrl());
			// 判断此标签是否有超链接
			// if (S.isNotEmpty(labelBean.getUrl())) {
			// infoView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
			// infoView.setTextColor(Color.BLUE);
			// setOnClickListener(infoView, labelBean.getUrl());
			// }
			child1Layout.addView(child2Layout);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public int getViewNum() {
		// TODO Auto-generated method stub
		return this.viewNum;
	}
}
